package ui;

import io.GPSPoint;
import io.GPXFileParser;
import io.SimpleParser;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.List;
import java.util.Map;
import java.util.TooManyListenersException;

import javax.sound.sampled.ReverbType;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;


import org.openstreetmap.osm.data.MemoryDataSet;
import org.openstreetmap.osm.io.FileLoader;

import session.Session;

import actions.LoadGPSFilesAction;
import actions.Settings;
import actions.ZoomController;

public class CoordinatedPanel extends JComponent {

	private OSMPanel2 mapPanel = null;
	
	private SpeedPanel speedPanel = null;

	private CurrentZoom currentZoom = new CurrentZoom(-1, -1);

	private JSplitPane splitPane;

	private JPanel statusPanel;;

	public CoordinatedPanel(Map<String, List<GPSPoint>> gpsTracks, Session session) {
		setLayout(new BorderLayout());
		statusPanel = new StatsPanel();
		
		mapPanel = new OSMPanel2(currentZoom, session); //TODO make better
		JPanel speedAndControlls = new JPanel(new BorderLayout());
		SpeedPanelControler control = new SpeedPanelControler(session);
		speedPanel = new SpeedPanel(gpsTracks, control);
		
		JPanel cntrlAndStatus = new JPanel();
		cntrlAndStatus.setLayout(new BorderLayout());
		cntrlAndStatus.add(control, BorderLayout.CENTER);
		cntrlAndStatus.add(statusPanel, BorderLayout.SOUTH);
		speedAndControlls.add(speedPanel, BorderLayout.CENTER);
		speedAndControlls.add(cntrlAndStatus, BorderLayout.EAST);
		
		speedAndControlls.setPreferredSize(new Dimension(150, 100));
		splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		splitPane.add(speedAndControlls);
		
		
		JPanel lowerPanel = new JPanel();
		lowerPanel.setLayout(new BoxLayout(lowerPanel, BoxLayout.Y_AXIS));
		lowerPanel.add(mapPanel);
		//SettingPanel comp = new SettingPanel(session);
		//lowerPanel.add(comp);
		
		splitPane.add(lowerPanel);
		splitPane.setDividerLocation(300);
		add(splitPane);
		Settings.getInstance().getPropertyChangeSupport().addPropertyChangeListener(new LoadGPSFilesAction());
		Settings.getInstance().getPropertyChangeSupport().addPropertyChangeListener(new ZoomController(currentZoom, mapPanel, speedPanel));
		//repaint();
	}
	
}
